package com.aerozhonghuan.logisticsmall.modules.mine.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aerozhonghuan.logisticsmall.R;
import com.aerozhonghuan.logisticsmall.modules.mine.beans.MenuItem;

import java.util.List;

/**
 * 描述 个人中心通用item Adapter
 *
 * @author zhangyonghui
 * 创建日期 2019-05-23
 */
public class RowItemAdapter extends BaseAdapter {
    private List<MenuItem> items;
    private LayoutInflater mLayoutInflater;

    public RowItemAdapter(List<MenuItem> datasource, Context context) {
        this.mLayoutInflater = LayoutInflater.from(context);
        items = datasource;
    }

    @Override
    public int getCount() {
        return items == null ? 0 : items.size();
    }

    @Override
    public MenuItem getItem(int position) {
        return items == null ? null : items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = (ViewGroup) mLayoutInflater.inflate(R.layout.mine_fragment_item, null);
            viewHolder = new ViewHolder();
            viewHolder.imageview_pic = (ImageView) convertView.findViewById(R.id.imageview_pic);

            viewHolder.textViewTitle = (TextView) convertView.findViewById(R.id.textview_title);
            viewHolder.textview_desc = (TextView) convertView.findViewById(R.id.textview_desc);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MenuItem item = getItem(position);
        if (item.iconID != 0) {
            viewHolder.imageview_pic.setImageResource(item.iconID);
        }
        viewHolder.textViewTitle.setText(item.title);
        viewHolder.textview_desc.setText(item.desc);
        return convertView;
    }

    public class ViewHolder {
        public ImageView imageview_pic;
        public TextView textViewTitle;
        public TextView textview_desc;
    }
}
